<!--
 * @Description: 
 * @Author: chenju
 * @Date: 2022-03-22 17:08:41
 * @LastEditors: chenju
 * @LastEditTime: 2022-04-14 19:58:46
-->
<template>
  <base-dialog
    :title="title"
    append-to-body
    destroy-on-close
    :width="600"
    :close-on-click-modal="false"
    v-model:visible="dialogVisible"
    @cancel="dialogVisible = false"
    :loading="loading"
    :showCancelButton="false"
    :confirmText="'我知道了'"
    @confirm="dialogVisible = false"
  >
    <div class="edit-op-container" v-if="dialogVisible">
      <p>
        已勾选排放源中有{{ dataMain.skipNum }}条已处于{{
          props.info?.title == 'ENABLE' ? '启用' : '停用'
        }}状态，本次{{ props.info?.title == 'ENABLE' ? '启用' : '停用'
        }}{{ dataMain.successNum }}条，有{{ dataMain.failNum }}条不可{{
          props.info?.title == 'ENABLE' ? '启用' : '停用'
        }}。
      </p>
      <div class="main">
        <div
          class="main-top"
          :style="!showMain ? 'border-radius: 4px;border-bottom: 1px solid #e4e7ed;' : ''"
        >
          <b>
            <CIcon
              v-if="showMain"
              type="c-xian-xia"
              @click="showMain = false"
              class="c-xian-xia"
            ></CIcon>
            <CIcon v-else type="c-xian-you" @click="showMain = true" class="c-xian-xia"></CIcon>
            <span>操作结果({{ dataMain.resultList.length }})</span>
          </b>
          <strong>
            <!-- <CIcon type="c-mian-tishi" style="color: #004cb3; margin-right: 5px"></CIcon>
            <span>失败说明</span> -->
          </strong>
        </div>
        <div class="main-cent" v-if="showMain">
          <span class="list1">操作结果</span>
          <span class="list2">排放源编号</span>
          <span class="list3">排放源名称</span>
        </div>
        <div class="main-btm" v-if="showMain">
          <div class="main-btm-list" v-for="(itm, i) in dataMain.resultList" :key="i">
            <span class="list1">
              <i
                :class="
                  itm.updateResult == 'SUCCESS'
                    ? 'btn-col'
                    : itm.updateResult == 'FAIL'
                    ? 'btn-col1'
                    : 'btn-col2'
                "
              >
                {{
                  itm.updateResult == 'SUCCESS'
                    ? '成功'
                    : itm.updateResult == 'FAIL'
                    ? '失败'
                    : itm.updateResult == 'SKIP' && props.info?.title == 'ENABLE'
                    ? '已启用'
                    : '已停用'
                }}
              </i>
              <el-tooltip
                class="box-item"
                effect="dark"
                :content="itm.failReason"
                placement="top-start"
                v-if="itm.updateResult == 'FAIL'"
              >
                <CIcon type="c-xian-shuoming" style="margin-left: 5px"></CIcon>
              </el-tooltip>
            </span>
            <span class="list2">{{ itm.sourceNo }}</span>
            <span class="list3">{{ itm.sourceName }}</span>
          </div>
        </div>
      </div>
    </div>
  </base-dialog>
</template>
<script lang="ts">
export default {
  name: 'AddOrEditTaskDialog'
};
</script>
<script lang="ts" setup>
import { defineProps, withDefaults, defineEmits, computed, ref, watch, reactive } from 'vue';
import { BaseDialog } from '@/components/BaseDialog/index';

interface SelectFillTypeDialogProps {
  visible: boolean;
  info: undefined | any;
}
const props = withDefaults(defineProps<SelectFillTypeDialogProps>(), {});
const emit = defineEmits(['update:visible', 'refresh']);
const dialogVisible = computed<boolean>({
  get: () => {
    return props.visible;
  },
  set: val => {
    emit('update:visible', val);
  }
});
const title = computed(() => {
  if (props.info?.title == 'ENABLE') {
    return '启用结果';
  } else {
    return '停用结果';
  }
});
watch(
  () => dialogVisible.value,
  visible => {
    if (visible) {
      init();
    } else {
      formRef.value?.resetFields();
    }
  }
);

const loading = ref(false);
const showMain = ref(false);

const formRef = ref();
const titInner = ref();
const dataMain = ref();

function handleConfirm() {
  loading.value = false;
  formRef.value?.resetFields();
}
function init() {
  loading.value = false;
  formRef.value?.resetFields();
  dataMain.value = props.info;
}
</script>
<style lang="scss" scoped>
p {
  margin-bottom: 28px;
}
.c-xian-xia {
  // transform: rotate(-90deg);
  margin-right: 4px;
  cursor: pointer;
}
.btn-col {
  width: 38px;
  height: 20px;
  background: #e7faee;
  border-radius: 2px;
  border: 1px solid #00c048;
  font-style: normal;
  font-size: 12px;
  font-family: SourceHanSansCN-Regular, SourceHanSansCN;
  font-weight: 400;
  color: #00c048;
  line-height: 20px;
  text-align: center;
}
.btn-col1 {
  width: 38px;
  height: 20px;
  background: #fff4e6;
  border-radius: 2px;
  border: 1px solid #ee8b00;
  font-style: normal;
  font-size: 12px;
  font-family: SourceHanSansCN-Regular, SourceHanSansCN;
  font-weight: 400;
  color: #ee8b00;
  line-height: 20px;
  text-align: center;
}
.btn-col2 {
  width: 48px;
  height: 20px;
  background: #f6f9fa;
  border-radius: 2px;
  border: 1px solid #ced4da;
  font-style: normal;
  font-size: 12px;
  font-family: SourceHanSansCN-Regular, SourceHanSansCN;
  font-weight: 400;
  color: #ced4da;
  line-height: 20px;
  text-align: center;
}
.main {
  width: 552px;
  max-height: 563px;
  border-radius: 4px;
  border: 1px solid #e4e7ed;
  border-bottom: 0;
  .main-top {
    width: 550px;
    height: 48px;
    background: #f6f9fa;
    border-radius: 4px 4px 0px 0px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    b > span {
      height: 10px;
      font-size: 14px;
      font-family: SourceHanSansCN-Bold, SourceHanSansCN;
      font-weight: bold;
      color: #212529;
      line-height: 10px;
    }
    strong > span {
      height: 10px;
      font-size: 14px;
      font-family: SourceHanSansCN-Regular, SourceHanSansCN;
      font-weight: 400;
      color: #004cb3;
      line-height: 10px;
    }
  }
}
.main-cent {
  height: 32px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #e4e7ed;
  font-size: 12px;
  font-family: SourceHanSansCN-Medium, SourceHanSansCN;
  font-weight: 500;
  color: #212529;
}
.main-btm-list {
  height: 40px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #e4e7ed;
  font-size: 14px;
  font-family: SourceHanSansCN-Regular, SourceHanSansCN;
  font-weight: 400;
  color: #51596c;
}
.list1 {
  width: 100px;
  margin-left: 20px;
  display: flex;
  align-items: center;
}
.list2 {
  width: 240px;
  margin-left: 20px;
}
.list3 {
  width: 210px;
  margin-left: 20px;
}
</style>
